﻿#include"main.hpp"

int tnum = 0;
void start()
{
	FILE* testio, * stuio;
	if ((testio = fopen("tests.txt", "rb")) == NULL)
	{
		FILE* pul = fopen("tests.txt", "wb");
		fwrite(tt, sizeof(test), 10, pul);
		fclose(pul);
		testio = fopen("tests.txt", "rb");
	}
	if ((stuio = fopen("stugrd.txt", "rb")) == NULL)
	{
		FILE* pul = fopen("stugrd.txt", "wb");
		fwrite(stu, sizeof(student), 10 * MAX, pul);
		fclose(pul);
		stuio = fopen("stugrd.txt", "rb");
	}
	fread(tt, sizeof(test), 11, testio);
	fread(stu, sizeof(student), 10 * MAX, stuio);
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < MAX; j++)
		{
			if (stu[i][j].state != 1) {
				tt[i].alrstu = j - 1;
				if (tt[i].alrstu < 0) tt[i].alrstu = 0;
				break;
			}
		}
	}
	for (int i = 0; i < 10; i++) if (tt[i].state != 1) {
		tnum = i - 1;
		if (tnum < 0) tnum = 0;
		break;
	}
}
